home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvmouse.exe / TMOUSE.CPP < prev    next >
C/C++ Source or Header  |  1993-01-03  |  4KB  |  238 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tmouse.cpp                                */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TMouse and THWMouse member functions      */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TEvent
  19. #include <tv.h>
  20.  
  21. #if !defined( __DOS_H )
  22. #include <Dos.h>
  23. #endif  // __DOS_H
  24.  
  25. #include "mouse.h"
  26.  
  27. uchar near THWMouse::buttonCount = 0;
  28. Boolean near THWMouse::handlerInstalled = False;
  29.  
  30. THWMouse::THWMouse()
  31. {
  32.     resume();
  33. }
  34.  
  35. void THWMouse::resume()
  36. {
  37.     OpenMouse ();
  38.  
  39.     buttonCount = 2;    // Must be fixed
  40.  
  41.     #if 0
  42.     if( getvect( 0x33 ) == 0 )
  43.         return;
  44.  
  45.     _AX = 0;
  46.     geninterrupt( 0x33 );
  47.  
  48.     if( _AX == 0 )
  49.         return;
  50.     buttonCount = _BL;
  51.  
  52.     _AX = 4;
  53.     _CX = 0;
  54.     _DX = 0;
  55.     geninterrupt( 0x33 );
  56.     #endif
  57. }
  58.  
  59. THWMouse::~THWMouse()
  60. {
  61.     suspend();
  62. }
  63.  
  64. void THWMouse::suspend()
  65. {
  66.     if( present() == False )
  67.         return;
  68.     hide();
  69.     if( handlerInstalled == True )
  70.         {
  71.         registerHandler( 0, 0 );
  72.         handlerInstalled = False;
  73.         }
  74.     buttonCount = 0;
  75.  
  76.     CloseMouse ();
  77. }
  78.  
  79. #pragma warn -asc
  80.  
  81. void THWMouse::show()
  82. {
  83.     #if 1
  84.  
  85.         asm push ax;
  86.         asm push es;
  87.         asm push ds;
  88.         asm push bx;
  89.         asm push si;
  90.         asm push di;
  91.         asm push cx;
  92.         asm push dx;
  93.         asm push bp;
  94.  
  95.         ShowMouse ();
  96.  
  97.         asm pop bp;
  98.         asm pop dx;
  99.         asm pop cx;
  100.         asm pop di;
  101.         asm pop si;
  102.         asm pop bx;
  103.         asm pop ds;
  104.         asm pop es;
  105.         asm pop ax;
  106.  
  107.     #else
  108.         asm push ax;
  109.         asm push es;
  110.        
  111.         if( present() )
  112.             {
  113.             _AX = 1;
  114.             geninterrupt( 0x33 );
  115.             }
  116.  
  117.         asm pop es;
  118.         asm pop ax;
  119.     #endif
  120. }
  121.  
  122. void THWMouse::hide()
  123. {
  124.     #if 1
  125.  
  126.         asm push ax;
  127.         asm push es;
  128.         asm push ds;
  129.         asm push bx;
  130.         asm push si;
  131.         asm push di;
  132.         asm push cx;
  133.         asm push dx;
  134.         asm push bp;
  135.        
  136.         HideMouse ();
  137.  
  138.         asm pop bp;
  139.         asm pop dx;
  140.         asm pop cx;
  141.         asm pop di;
  142.         asm pop si;
  143.         asm pop bx;
  144.         asm pop ds;
  145.         asm pop es;
  146.         asm pop ax;
  147.  
  148.     #else
  149.  
  150.         asm push ax;
  151.         asm push es;
  152.        
  153.         if( buttonCount != 0 )
  154.             {
  155.             _AX = 2;
  156.             geninterrupt( 0x33 );
  157.             }
  158.  
  159.         asm pop es;
  160.         asm pop ax;
  161.  
  162.     #endif
  163. }
  164.  
  165. #pragma warn .asc
  166.  
  167. void THWMouse::setRange( ushort rx, ushort ry )
  168. {
  169.     if( buttonCount != 0 )
  170.         {
  171.         SetMouseRange (0, rx, 0, ry);
  172.         SetMouseScreenDimensions (rx+1, ry+1);
  173.  
  174.         #if 0
  175.         _DX = rx;
  176.         _DX <<= 3;
  177.         _CX = 0;
  178.         _AX = 7;
  179.         geninterrupt( 0x33 );
  180.  
  181.         _DX = ry;
  182.         _DX <<= 3;
  183.         _CX = 0;
  184.         _AX = 8;
  185.         geninterrupt( 0x33 );
  186.         #endif
  187.         }
  188. }
  189.  
  190. void THWMouse::getEvent( MouseEventType& me )
  191. {
  192.     MouseInfo    mi;
  193.  
  194.     ReadMouse (&mi);
  195.     me.buttons = mi.Buttons;
  196.     me.where.x = mi.X;
  197.     me.where.y = mi.Y;
  198.     me.doubleClick = False;
  199.  
  200.     #if 0
  201.     _AX = 3;
  202.     geninterrupt( 0x33 );
  203.     _AL = _BL;
  204.     me.buttons = _AL;
  205.     me.where.x = _CX >> 3;
  206.     me.where.y = _DX >> 3;
  207.     me.doubleClick = False;
  208.     #endif
  209. }
  210.  
  211. void THWMouse::registerHandler( unsigned mask, void (far *func)() )
  212. {
  213.     if( !present() )
  214.         return;
  215.  
  216. #if defined( ProtectVersion )
  217.     _AX = 20;
  218. #else
  219.     _AX = 12;
  220. #endif
  221.     _CX = mask;
  222.     _DX = FP_OFF( func );
  223.     _ES = FP_SEG( func );
  224.     geninterrupt( 0x33 );
  225.     handlerInstalled = True;
  226. }
  227.  
  228. TMouse::TMouse()
  229. {
  230.     show();
  231. }
  232.  
  233. TMouse::~TMouse()
  234. {
  235.     hide();
  236. }
  237.  
  238.